<?php
class sw_valuta_model extends MY_Model {
	var $model = 'sw_valuta';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	* 
					FROM	SW_VALUTA 
					WHERE	(KD_VALUTA LIKE '%".post('keyword')."%'
							OR NOTASI LIKE '%".post('keyword')."%'
							OR NAMA_VALUTA LIKE '%".post('keyword')."%')
					ORDER BY ".(post('sort')=='' ? 'KD_VALUTA' : post('sort'))." ".(post('order')=='' ? 'ASC' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function GetCurrency($as_kd_valuta='%'){
		$ls_sql = "SELECT * FROM SW_VALUTA WHERE KD_VALUTA LIKE '%".$as_kd_valuta."%'";
		$result	= $this->db->query($ls_sql);
		
		if($result->num_rows() > 0){
			$arr_data	= $result->result_array();
			return $arr_data;
		}else{
			return NULL;
		}
	}	
	
	
	function Add($arr_data){
		$this->db->insert('SW_VALUTA', $arr_data);
	}
	
	function Update($arr_data, $arr_currency){
		$this->db->update('SW_VALUTA', $arr_data, $arr_currency);
	}
	
	function GetSingle($as_code){
		$result = $this->db->get_where('SW_VALUTA', array('KD_VALUTA' => $as_code));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_code)
	{
		$result = $this->db->get_where('SW_VALUTA', array('KD_VALUTA' => $as_code));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($as_code)
	{
		try {
				$this->db->delete('SW_VALUTA', array('KD_VALUTA' => $as_code));
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>